JSON Schemas#

Included in the directory /Utilities/json_schemas are JSON schema files defining the YAML configuration files’ structure. The models.py file in that directory uses Pydantic to automatically generate the schema files based on the model classes defined within it.

A YAML loader class, TagFreeLoader, is implemented and used to preserve the original structure and typings of the YAML data.

Important

models.py depends on pydantic, which is not included in the arcgispro-py3 environment prior to ArcGIS Pro 3.4.

Running models.py#

usage: models.py [-h] [--no-emit] [--quiet]

options:
  -h, --help  show this help message and exit
  --no-emit   Do not write JSON schema files
  --quiet     Do not print validation results

models.py Reference#

Script containing Pydantic models for YAML configuration files.

Note

models.py does not depend on ng911ok.

This script is intended to read, validate, and generate JSON schemas for all configuration files included in the Toolkit. The TagFreeLoader class ignores all YAML tags, so the data types used in the Pydantic models correspond to the types of the values in the actual YAML files before they are processed by the Toolkit.

The model classes should have attributes corresponding to keys in the YAML files, and the attributes should have type hints similar to:

Annotated[int, Field(description="Some integer")]

In the above case, int is the attribute’s type, and Field(description="Some integer") provides additional information to Pydantic. The description argument is used to generate the values of description keys for each item of properties keys in the output JSON schemas.

PATH_TOOLKIT_ROOT: Final[Path] = WindowsPath('G:/ArcGIS/Project Files/NG911/NG911_Pro/NG911-Pro')#

The root folder of the Toolkit.

PATH_SCHEMA_ROOT: Final[Path] = WindowsPath('G:/ArcGIS/Project Files/NG911/NG911_Pro/NG911-Pro/Utilities/json_schemas')#

The folder to which JSON schema files should be written.

class TagFreeLoader(stream)#

YAML loader that ignores tags.

construct_object(node, deep=False)#

Attempts to construct an object from node as normal. If a yaml.constructor.ConstructorError occurs, attempts to construct node as if it has no tag.

validate_file(path: Path, model: type[BaseModel] | TypeAdapter, quiet: bool = True, out_schema_file: str | None = None) bool#

Validates a YAML configuration file against a Pydantic model. Optionally prints the result of the validation and exports a JSON schema file.

Parameters:
  • path – Path to the YAML configuration file

  • model – Subclass of BaseModel or instance of TypeAdapter against which the data in path should be validated

  • quiet – If True, prints nothing to the console; default False

  • out_schema_file – If supplied (and the data passes validation), the name of the JSON schema file to create in the PATH_SCHEMA_ROOT` directory

Returns:

Whether the contents of the file at path passed validation